package middle;

import java.util.ArrayList;
import java.util.List;

public class Solution_386 {

    public static void main(String[] args) {
        Solution_386 model = new Solution_386();
        System.out.println(model.lexicalOrder(13));
        System.out.println(model.lexicalOrder(2));
        System.out.println(model.lexicalOrder(1));
        System.out.println(model.lexicalOrder(100));
    }

    private List<Integer> list;
    public List<Integer> lexicalOrder(int n) {
        list = new ArrayList<>(n);
        dps(0, n);
        return list;
    }

    private void dps(int base, int limit) {
        if (base > limit) {
            return;
        }
        if (base > 0) {
            list.add(base);
        }
        for (int i = 0; i <= 9; i++) {
            if (base > 0 || i > 0) {
                dps(base * 10 + i, limit);
            }
        }
    }
}
